<template>
	<div class="zy-content dataBoard">
		<Page @orgChange="orgChange" @deviceTypeChange="deviceTypeChange" :showDeviceType="true">
			<div class="content">
				<div class="top">
					<Widget title="全局OEE" style="flex: 1">
						<div class="card-left">
							<Chart2 :value="oeeRate.oee" />
						</div>
						<div class="info">
							<card-style-1 info1="目标值" :info2="oeeRate.target + '%'"></card-style-1>
							<card-style-1 :info1="`偏差值`" :info2="(oeeRate.oee - oeeRate.target).toFixed(2) + '%'"></card-style-1>
						</div>
					</Widget>
					<Widget title="全局时间稼动率" style="flex: 1">
						<div class="card-left">
							<Chart2 :value="oeeRate.timeCropMovement" />
						</div>
						<div class="info">
							<card-style-1 info1="目标值" :info2="oeeRate.target + '%'"></card-style-1>
							<card-style-1 :info1="`偏差值`" :info2="(oeeRate.timeCropMovement - oeeRate.target).toFixed(2) + '%'"></card-style-1>
						</div>
					</Widget>
					<Widget title="全局性能稼动率" style="flex: 1">
						<div class="card-left">
							<Chart2 :value="oeeRate.performanceCropMovement" />
						</div>
						<div class="info">
							<card-style-1 info1="目标值" :info2="oeeRate.target + '%'"></card-style-1>
							<card-style-1 :info1="`偏差值`" :info2="(oeeRate.performanceCropMovement - oeeRate.target).toFixed(2) + '%'"></card-style-1>
						</div>
					</Widget>
					<Widget title="全局合格率" style="flex: 1">
						<div class="card-left">
							<Chart2 :value="oeeRate.passRate" />
						</div>
						<div class="info">
							<card-style-1 info1="目标值" :info2="oeeRate.target + '%'"></card-style-1>
							<card-style-1 :info1="`偏差值`" :info2="(oeeRate.passRate - oeeRate.target).toFixed(2) + '%'"></card-style-1>
						</div>
					</Widget>
				</div>
				<div class="bottom">
					<Widget title="OEE趋势图" style="flex: 1.8">
						<template #toolbar>
							<Tags>
								<Tag type="out" color="#2564ba">OEE</Tag>
								<Tag type="out" color="#9cbf5a">合格率</Tag>
								<Tag type="out" color="#d3931e">时间稼动率</Tag>
								<Tag type="out" color="#2c9fe5">性能稼动率</Tag>
							</Tags>
						</template>
						<div style="flex: 1; height: 100%">
							<Chart3 v-model="oeeMonth" ref="chart3" />
						</div>
					</Widget>
					<Widget title="设备OEE" key="设备OEE" style="flex: 1">
						<template #toolbar>
							<Tags>
								<Tag type="out" color="#3974f6">时间稼动率</Tag>
								<Tag type="out" color="#63c68d">性能稼动率</Tag>
								<Tag type="out" color="#aeb9d0">合格率</Tag>
							</Tags>
						</template>
						<div class="device-oee">
							<card-style-2 v-for="(item, index) in deviceCodeOeeList" :key="index" :info1="item.title" :info2="item.list" />
						</div>
					</Widget>
				</div>
			</div>
		</Page>
	</div>
</template>

<script>
import Page from '@/components/dataBoard/layout/page/index.vue';
import Widget from '@/components/dataBoard/components/widget/index.vue';
import Tags from '@/components/dataBoard/components/tags/index.vue';
import Tag from '@/components/dataBoard/components/tag/index.vue';
import CardStyle1 from './components/card-style1.vue';
import CardStyle2 from './components/card-style2.vue';
// import Chart1 from "./components/chart1.vue";
import Chart2 from './components/chart2.vue';
import Chart3 from './components/chart3.vue';

export default {
	name: 'oeeBoard1',
	components: {
		Page,
		Widget,
		Tags,
		Tag,
		CardStyle1,
		CardStyle2,
		// Chart1,
		Chart2,
		Chart3,
	},
	data() {
		return {
			isFull: false,
			workShop: ' ',
			deviceCategory:'',
			value: 10,
			oeeData: {},
			deviceOee: {},
			deviceCodeOeeList: [],
			interval: null,
			oeeMonth: {},
			oeeRate: {
				oee: 0,
				passRate: 0,
				performanceCropMovement: 0,
				target: 0,
				timeCropMovement: 0,
			},
			// deviceOeeTotal: {
			//   title: deviceOee.deviceCode,
			//   list: [
			//     { label: "时间稼动率", value: deviceOee.time },
			//     { label: "性能稼动率", value: deviceOee.time },
			//     { label: "合格率", value: deviceOee.time }
			//   ]
			// }
		};
	},
	watch: {
		isFull(val) {
			this.$nextTick(() => {
				this.$refs.chart3.resize();
			});
		},
		// workShop() {
		// 	this.getOeeData();
		// },
	},
	mounted() {
		this.getOeeData();
		this.interval=setInterval(() => {
			this.getOeeData();
		}, 1000 * 30);
	},
	beforeDestroy() {
		clearInterval(this.interval);
	},
	methods: {
		// 车间改变获取车间code
		orgChange(val) {
			this.workShop = val;
			this.getOeeData();
		},
		deviceTypeChange(val) {
			this.deviceCategory = val;
			this.pageNum = 1;
			this.getOeeData();
		},
		getOeeDevice() {
			this.axios({
				url: '/dms/oee-board/oeeDevice',
				method: 'get',
				params: {
					deviceCategory: this.deviceCategory,
					workShop: this.workShop || ' ',
				},
			}).then((res) => {
				this.deviceCodeOeeList = res.data.map((item) => {
					return {
						title: item.deviceNo,
						list: [
							{ label: '时间稼动率', value: item.timeCropMovement },
							{ label: '性能稼动率', value: item.performanceCropMovement },
							{ label: '合格率', value: item.passRate },
						],
					};
				});
			});
		},
		getOeeMonth() {
			this.axios({
				url: '/dms/oee-board/oeeMonth',
				method: 'get',
				params: {
					workShop: this.workShop || ' ',
					deviceCategory: this.deviceCategory,
				},
			}).then((res) => {
				const data = res.data || [];
				if (res.code == 200) {
					this.oeeMonth.oee = data.map((item) => item.oee);
					this.oeeMonth.days = data.map((item) => item.date);
					this.oeeMonth.passRate = data.map((item) => item.passRate);
					this.oeeMonth.timeCropMovement = data.map((item) => item.timeCropMovement);
					this.oeeMonth.performanceCropMovement = data.map((item) => item.performanceCropMovement);
					this.$refs.chart3.initChart();
				} else {
					this.$Message.error(res.msg);
				}
			});
		},
		getOeeRate() {
			this.axios({
				url: '/dms/oee-board/oeeRate',
				method: 'get',
				params: {
					workShop: this.workShop || ' ',
					deviceCategory: this.deviceCategory,
				},
			}).then((res) => {
				if (!res.data) {
					this.oeeRate = {
						oee: 0,
						passRate: 0,
						performanceCropMovement: 0,
						target: 0,
						timeCropMovement: 0,
					};
				} else this.oeeRate = res.data;
			});
		},
		getOeeData() {
			this.getOeeMonth();
			this.getOeeRate();
			this.getOeeDevice();
		},
	},
};
</script>
<style>
.dataBoard {
	background-color: #e6eaf0 !important;
}
</style>
<style scoped lang="scss">
.dataBoard {
	height: 100%;
	width: 100%;
	overflow-y: scroll;
	&::-webkit-scrollbar {
		width: 0.7em !important; /* 设置滚动条的宽度 */
	}

	&::-webkit-scrollbar-track {
		background-color: #e6eaf0 !important; /* 设置背景色 */
	}

	&::-webkit-scrollbar-thumb {
		background-color: #e6eaf0 !important; /* 设置滑块的颜色 */
	}

	/* 隐藏垂直滚动条 */
	&::-webkit-scrollbar-vertical {
		display: none; /* 将其显示为none来隐藏 */
	}
	.content {
		height: 99%;
		display: flex;
		flex-direction: column;
		.top {
			height: 200px;
			display: flex;
			flex-direction: row;
			gap: 10px;
			.info {
				flex: 3;
				margin: 10px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				// justify-content: space-around;
				gap: 10px;
			}
			.card-left {
				justify-content: center;
				flex: 2;
				height: 90% !important;
				margin: 7px;
			}
		}
		.bottom {
			flex: 1;
			gap: 10px;
			display: flex;
			flex-direction: row;
		}
		// display: flex;
		// flex-direction: column;
	}
	// background-color: red !important;
}

.device-oee {
	max-height: calc(95vh - 300px);
	// height: 100%;
	min-height: 0;
	overflow: hidden;
	width: 100%;
	overflow-y: scroll;
	display: flex;
	flex-direction: column;
	padding: 10px;
	margin: -3px;
	gap: 10px;
	&::-webkit-scrollbar {
		width: 0.7em !important; /* 设置滚动条的宽度 */
	}

	&::-webkit-scrollbar-track {
		background-color: #e6eaf0 !important; /* 设置背景色 */
	}

	&::-webkit-scrollbar-thumb {
		background-color: #e6eaf0 !important; /* 设置滑块的颜色 */
	}
}
</style>
